<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <div class="table-operator">
                <a-button v-btnPermission="'tm_009_add_01'" type="primary" icon="plus" @click="handleUpdate('add', {})">新增会议</a-button>
            </div>
            <div class="pub-table-select-count">
                <a-icon type="info-circle" theme="twoTone"/>
                <span>施组方案总数：</span>
                <a>{{ totalInfo.allNumberSZ || 0 }}</a>
                <span>{{ ' | ' }}A类方案总数：</span>
                <a>{{ totalInfo.allNumberA || 0 }}</a>
                <span>{{ ' | ' }}已评审方案数：</span>
                <a>{{ totalInfo.completeNum || 0 }}</a>
                <span>{{ ' | ' }}方案评审率：</span>
                <a>{{ totalInfo.completeRate || 0 }}%</a>
            </div>
            <s-table
                ref="table"
                size="default"
                rowKey="key"
                :columns="columns"
                :data="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <span slot="operation" slot-scope="text, record">
                    <a @click="handleUpdate('start', record)" v-if="record.status == 20" v-btnPermission="'tm_009_edi_02'">查看会议</a>
                    <a @click="handleUpdate('edit', record)" v-if="record.status == 30" v-btnPermission="'tm_009_edi_02'">进入会议</a>
                    <a @click="handleUpdate('look', record)" v-if="record.status == 40" v-btnPermission="'tm_009_loo_03'">查看会议</a>
                </span>
                <span slot="commentedPlan" slot-scope="text, record">
                    {{ record.meetingExtraVO.commentedPlan }}
                </span>
                <span slot="professionComName" slot-scope="text, record">
                    {{ record.meetingExtraVO.professionComName }}
                </span>
                <span slot="avgScore" slot-scope="text, record">
                    {{ record.meetingExtraVO.avgScore }}
                </span>

                <span slot="status" slot-scope="text, record">
                    <list-status :status="record.status" conversion="en" :text="text"></list-status>
                </span>
            </s-table>
        </a-card>
    </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import { STable } from '@/components'
import listStatus from '@/components/list_status/meeting_status'
import { getMeetingList, startMeeting,getSearchList } from '@/api/office/conference'
import { getmeetingTotal } from '@/api/technical/meeting.js'

const columns = [
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    {
        title: '方案名称',
        dataIndex: 'commentedPlan',
        scopedSlots: { customRender: 'commentedPlan' },
    },
    {
        title: '评审得分',
        dataIndex: 'avgScore',
        scopedSlots: { customRender: 'avgScore' },
    },

    {
        title: '主持人',
        dataIndex: 'speaker',
    },
    {
        title: '召开时间',
        dataIndex: 'startTime',
    },
    {
        title: '状态',
        dataIndex: 'status',
        scopedSlots: { customRender: 'status' },
    },

    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '方案名称',
        value: 'commentedPlan',
        type: 'select',
        data: [],
    },

    {
        name: '讲解人',
        value: 'speakerName',
        type: 'input',
    },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: [
            {
                value: '20',
                label: '待开始',
            },
            {
                value: '30',
                label: '进行中',
            },
           
            {
                value: '40',
                label: '已完结',
            },
        ],
    },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input',
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
]
export default {
    name:'a'+Date.now(),    components: {
        STable,
        listStatus,
    },
    data() {
        this.columns = columns

        return {
            totalInfo: {}, // 统计信息
            searchArr: [],
            queryParam: {},
            loadData: async (parameter) => {
                this.queryParam.query = { ...this.queryParam.query, typeId: 1 }
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getmeetingTotalReq(requestParameters) // 调用统计接口
                const [err, res] = await getMeetingList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            },
        }
    },
    mounted() {
        this.getSearchListReq()
    },
    methods: {
        /**
         * 获取统计信息
         */
        async getmeetingTotalReq(extra = {}) {
            try {
                const params = {
                    ...extra,
                    ...extra.query,
                    typeId: 1
                }
                const res = await getmeetingTotal(params)
                this.totalInfo = res.data || {}
                this.totalInfo.completeRate = (this.totalInfo.completeRate * 100).toFixed(2)
            } catch(e) {
                console.error(e)
            }
        },
        async getSearchListReq() {
            const [err, res] = await getSearchList({ typeId: 1 })
            if (!err) {
                res.data.forEach((item) => {
                    item.value = item.id
                    item.label = item.name
                })
                searchArr[2].data = res.data || []
               
            }
             this.searchArr = searchArr
        },
        //搜索
        search(val = {}) {
            this.queryParam.query = {
                ...val,
                typeId: 1,
                hsemonth: (val.month && val.month.format('YYYY-MM')) || void 0,
                startTime:
                    (val.startEndDate &&
                        val.startEndDate.length &&
                        val.startEndDate[0].format('YYYY-MM-DD')) ||
                    void 0,
                endTime:
                    (val.startEndDate &&
                        val.startEndDate.length &&
                        val.startEndDate[1].format('YYYY-MM-DD')) ||
                    void 0,
            }
            console.log(this.queryParam)

            this.$refs.table.refresh(true)
        },

        // 处理更新操作（新增、编辑）
        async handleUpdate(type, data = {}) {
            if (type == 'del') {
                // const [err, res] = await deleteEquipment({ id: data.id })
                // if (!err) {
                //     this.$message.success('成功')
                //     this.$refs.table.refresh(true)
                // }
            } 
            // else if (type == 'start') {
            //     const [err, res] = await startMeeting({ id: data.id })
            //     if (!err) {
            //         this.$message.success('成功')
            //         this.$refs.table.refresh(true)
            //     }
            // } 
            else if (type == 'edit' || type == 'look'||type == 'start') {
                this.$router.push({
                    name: 'reviewMeetingCheck',
                    query: {
                        id: data.id || '',
                        pageType: type,
                    },
                })
            } else {
                this.$router.push({
                    name: 'technicalAddConference',
                    query: {
                        id: data.id || '',
                        pageType: type,
                        typeId: 1,
                    },
                })
            }
        },
    },
}
</script>
